package com.example.ch02;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AnswerActivity extends AppCompatActivity {

    //用于展示传过来的问题和输入的答案
    private TextView tv_answer_back;
    private EditText et_answer_back;
    private Button btn_a;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer);
        tv_answer_back=(TextView)findViewById(R.id.tv_answer_back);
        et_answer_back=(EditText)findViewById(R.id.et_answer_back);
        btn_a=(Button)findViewById(R.id.btn_a);
        btn_a.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                passDateback();
            }
        });

        //获取传送的问题，解析并显示
        Intent intent=getIntent();
        String question=intent.getStringExtra("question");
        tv_answer_back.setText(question);
    }
    //回传时的方法
    public void passDateback(){
        Intent intent_back=new Intent();
        String answer=et_answer_back.getText().toString();
        intent_back.putExtra("answer",answer);
        setResult(1,intent_back);
        finish();//关闭页面
    }
}